package com.opentd.graphics.screen;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;

import javax.swing.ImageIcon;

import com.opentd.game.Game;
import com.opentd.graphics.Button;
import com.opentd.gui.Frame;

public class MainScreen extends Screen{
	
	
	
	public static Button startButton;
	public static Button levelSelectButton;
	public static Button quitButton;
	public static Image menuBG = new ImageIcon("dat/img/menu_bg.png").getImage();
	
	public static boolean isFirst = true;

	public static void draw(Graphics g) {
		if(isFirst){
			startButton = new Button(285, 75, Game.Button.START_BUTTON);
			levelSelectButton = new Button(285, 150, Game.Button.LEVEL_SELECT_BUTTON);
			quitButton = new Button(285, 400, Game.Button.QUIT_BUTTON);
			isFirst = false;
		}
		g.setColor(new Color(100, 100, 100));
		g.drawImage(menuBG, 0,  0, Game.panel.getWidth(), Game.panel.getHeight(),null);
		if(Game.selectedLevel == null){
			g.drawString("Selected Level: " + "No level selected", Game.panel.getWidth() - 250, Game.panel.getHeight() - 100);
		}else{
			g.drawString("Selected Level: " + Game.selectedLevel.title, Game.panel.getWidth() - 250, Game.panel.getHeight() - 100);
		}
		
		startButton.draw(g);
		levelSelectButton.draw(g);
		quitButton.draw(g);
	}
	
	public static void handleClick(Point p){
		if(startButton.contains(p)){
			if(Game.selectedLevel == null){
				Game.State.goToGameAfterSelectLevel = true;
				Game.State.currentScreen = Game.State.LEVEL_SELECT_SCREEN;
			}else{
				Game.State.currentScreen = Game.State.GAME_SCREEN;
			}
		} else if(levelSelectButton.contains(p)){
			Game.State.currentScreen = Game.State.LEVEL_SELECT_SCREEN;
		} else if(quitButton.contains(p)){
			Game.exit(true);
		}
	}
	
}
